﻿<% @ LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<% Option Explicit %>

<%
Dim fso,InDir,fileObject,fileCollection
Dim fInfo,thisFileName,thisFile,createdate,lastModifiedDate
Dim intDaysOld
InDir = Server.MapPath("/") & "\..\database\images"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileObject = fso.GetFolder(InDir)
Set fileCollection = fileObject.Files
'Set subfoldersCollection = fileObject.SubFolders

Response.Write(Date  & "<br />")
For Each fInfo In fileCollection
thisFileName = InDir & "\" & fInfo.Name
Set thisFile = fso.GetFile(thisFileName)
createdate = thisFile.DateCreated
lastModifiedDate = thisFile.DateLastModified

intDaysOld = cInt(Date - CreateDate)
'intDaysOld = cInt(Date - lastModifiedDate)
Response.Write("File - " & thisFileName & "<br />")
If intDaysOld > 14 Then
'wscript.echo thisFileName & " is " & intDaysOld & " days old.
'Deleting!"
fso.DeleteFile(thisFileName)
Response.Write("Deleted File - " & thisFileName & "<br />")
End If
Next
Response.Write("==========================================================================" & "<br />")
'' If you want it to go into subdirectories, uncomment below
'For Each fFolder In subfoldersCollection
'  FileSearch (InDir & "\" & fFolder.Name)
'Next
 %>